package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class AttrInfoController {

   @Autowired
   BaseAttrInfoService baseAttrInfoService;
   @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
   public Result getAttrInfoList(@PathVariable("category1Id") Long category1Id,
                                 @PathVariable("category2Id") Long category2Id,
                                 @PathVariable("category3Id") Long category3Id){
       List<BaseAttrInfo> baseAttrInfos =baseAttrInfoService.getAttrInfoList(category1Id,category2Id,category3Id);
       return Result.ok(baseAttrInfos);
   }

    /**
     * 保存/修改平台属性
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
   public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){

        baseAttrInfoService.saveOrUpdateAttrInfo(baseAttrInfo);

       return Result.ok();
    }

    /**
     * 根据id查询属性的名和值
     * @param attrId
     * @return
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        //BaseAttrInfo baseAttrInfo=baseAttrInfoService.getAttrValueListById(attrId);
        List<BaseAttrValue> attrValueList=baseAttrInfoService.findAttrValueListById(attrId);
        return Result.ok(attrValueList);
    }

}
